package dk.miljoeportalen.dkpunkt.migration;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;

public class MigrationServletContextListener {
	
	private MigrationManager migrationManager;
	
	@Autowired
	public void setMigrationManager(MigrationManager manager) {
		this.migrationManager = manager;
	}
	
    @PostConstruct
	public void contextInitialized() {
        try {
            migrationManager.migrate();
        }
        catch (Exception e) {
            throw new RuntimeException("Database migration failed", e);
        }
	}
}
